Project for Patterns and Trends in Environmental Data - Computational Movement Analysis
Author
Mirjam Scheib & Miriam Steinhauer
Published
July 2, 2023
1 To Do’s im Code
Rendern (Miri)
Summary tables nötig? bzw. wie am besten darstellen
Table beschriftungen? Nicht gleich wie figure beschriftung? Das geht nicht anders.. das haben sie im Best Practise auch so gemacht
2 BACKGROUND AND RESEARCH QUESTIONS
It is known that several factors like the weather condition (Brum-Bastos et al., 2018), the day of the week and time of the day (Liu et al., 2020; Sathishkumar et al., 2020) influence spatio-temporal movement patterns of people. There are several study’s investigating movement patterns of people in urban areas with the aim to improve the distribution of facilities and the provisioning of transportation services, as well as to manage traffic peaks (Kyaing et al., 2017; Liu et al., 2020). Nevertheless, most studies do not focus on specific social groups (e.g. workforce, students, pensioners), that might follow distinct spatio-temporal patterns, showing a potential demand for a specific adaption of infrastructure. The canton of Zurich accommodates the most students in Switzerland, with numbers continuing to rise (Bundesamt für Statistik, 2023). Additionally, students and apprentices (from the age of 15 years) make up 39 % of the public transport commuter mass, which is why knowledge of spatio-temporal patterns of students could help to manage train and other public transport infrastructure (Bundesamt für Statistik, 2021). Therefore, we want to investigate the influence of three environmental factors on spatio-temporal movement patterns of students, aiming to answer the following research questions:
Does the day of the week (weekend vs. workday) have an influence on the spatio-temporal movement patterns of students?
Does the time of the day compared between weekend and workday have an influence on the spatio-temporal movement patterns of students?
Does precipitation has an impact the spatio-temporal movement patterns of students?
3 DATA & METHODS
3.1 Data
Primary data used in this project work consisted of trajectory data from 11 students collected with the Posmo App containing the following attributes:
user_id: entails the individual ID of the user (= student) (type: character)
datetime: date and time when a position of a user is tracked (type: datetime)
weekday: abbreviated name of the weekday (e.g. Mon = Monday) (type: character)
place_name: names of a place, in which a user is at a specific time (type: character)
transport_mode: the type of transport used by a user (e.g. car, bicycle, foot, train, other….) (type: character)
lon_x/lat_y: coordinates of the user at a specific time (type: numeric)
Additionally, weather data from 84 stations in the canton of Zurich and bordering cantons (SZ, AG, ZG, TG, SG), consisting of measurements every 10 minutes was used to investigate the influence of precipitation on spatio-temporal movement patterns of students.
3.2 Pre-processing
For the analysis first we reviewed data consistency by creating a point plot, where every tracking point in time (x-axis) was displayed per user (y-axis). Five users needed to be eliminated due to insufficient tracking point coverage in time. Additionally, the dataset was cut into a specific timeframe (28.04.2023 - 09.05.2023) covering 11 days to ensure sufficient overlap of tracking points between users in time. Additionally, travel modes consisting of “Airplane”, “Funicular” and “Other1” were removed, as they presented either too specific or unspecific travel modes to be of interest in the subsequent analysis.
Furthermore, all convenience variables needed for the analysis were annotated in our pre-processing steps. First, it was discriminated between weekend (Sa – So) and weekdays (Mo – Fr). Additionally, to discriminate between days with high and low/no precipitation we calculated the nearest weather station for every trajectory point and annotated the precipitation data at the matching time to our dataset. We considered a precipitation of > 20 mm per 24 hours as a rainy day, as MeteoSwiss (n.d.) defines a precipitation from 10 – 30 mm per 24 hours as high intensity precipitation.
To investigate spatio-temporal movement patterns of students in concern to environmental variables, we discriminated between static and movement segments and assigned to every moving sequence a segment ID. From this we calculated distance, speed and duration for every segment.
All pre-processing steps can be accessed in a separate quarto-file (Pre_Processing.qmd) in our github respiratory under the following link: https://github.com/mirjamscheib/Semester_Project.git
3.3 Analysis
The analysis of the research questions was carried out by creating summary tables and boxplots to investigate distance, speed and duration of different travel modes comparing weekends with weekdays and precipitation with no precipitation. Additionally, line plots visualising distance, speed and duration per hour of the day comparing weekends with weekdays were carried out. Cartographic maps visualising trajectory points of students comparing weekends with weekdays and precipitation and no precipitation complement the analysis.
Code
# clear space rm(list=ls())# load packages library("readr")library("dplyr")library("ggplot2")library("sf")library("terra")library("tmap")library("gitcreds")library("dplyr")library("SimilarityMeasures")library("lubridate")library("plotly")# load clean data posmo <-read_delim("posmo_data/posmo_trips.csv")
Table 1: Overview over the mean speed, distance and duration of travel modes compared between weekdays and weekends, including their share
4.1.1 Spatial Analysis
For each travelmode we found a higher trip distance on weekends compared to weekdays. The trip distances for the travel mode “walk” have a lower mean than for other travel modes. On the other hand, the mean travel distances for “bike” are around the same range as for “car” and “train”.
Code
ggplot() +geom_boxplot(data = posmo, aes(day_week, log(trip_dis), fill = day_week)) +labs(title ="Trip Distance per Transport Mode", subtitle ="Comparing Weekend vs. Weekday", fill ="Day of the Week") +ylab("Log Trip Distance [m]") +xlab("Transport Mode") +scale_fill_manual(values =c("weekday"="lavenderblush3", "weekend"="aquamarine3"), labels =c( "Weekday", "Weekend")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())
Figure 1: Trip distance per transport mode compared between weekends and weekdays, the trip distance is logarythmised
For trip speed, the results are not as clear as for trip distance, but there is a tendency of trip speed being higher on the weekends, than during the week. Again we find the mean trip speed of “bike” being in a similar range as “car” and “train”, whereas “bus” conforms to “horse”.
Code
ggplot(posmo, aes(day_week, log(trip_speed), fill = day_week)) +geom_boxplot() +labs(title ="Trip Speed per Transport Mode", subtitle ="Comparing Weekend vs. Weekday", fill ="Day of the Week") +ylab("Log Speed [m/s]") +xlab("Transport Mode") +scale_fill_manual(values =c("weekday"="lavenderblush3", "weekend"="aquamarine3"), labels =c( "Weekday", "Weekend")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())
Figure 2: Trip speed per transport mode compared between weekends and weekdays, the trip speed is logarythmised
4.1.2 Temporal Analysis
We could not find a clear result concerning trip duration between weekends and weekdays. The only tendency that can be seen, is that the mean trip duration of “walk” is lower than for all the other travel modes.
Code
#| label: Boxplot comparing trip duration between weekend and weekday of travelmodesggplot() +geom_boxplot(data = posmo, aes(day_week, log(trip_duration/60), fill = day_week)) +labs(title ="Trip Duration per Transport Mode", subtitle ="Comparing Weekend vs. Weekday", fill ="Day of the Week") +ylab("Log Duration [min]") +xlab("Transport Mode") +scale_fill_manual(values =c("weekday"="lavenderblush3", "weekend"="aquamarine3"), labels =c( "Weekday", "Weekend")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())
Figure 3: Trip duration per transport mode compared between weekends and weekdays, the trip duration is logarythmised
Code
# transform posmo data into an sf object posmo <-st_as_sf(posmo, coords =c("X","Y"), crs =2056) # 1. add grouping variable to the sf objectposmo_grouped <-group_by(posmo, dataset)# 2. use summarise() to "dissolve" all point into a multipoint objectposmo_smry <-summarise(posmo_grouped)# 3. run st_convex_hull()mcp_posmo <-st_convex_hull(posmo_smry)# set visual modetmap_mode("view")# cartographic visualisation tm_shape(mcp_posmo) +tm_fill(col ="dataset", alpha =0.4, title ="Student") +tm_layout(title ="Cartographic Representation of Students travelling on Weekdays vs. Weekends") +tm_shape(mcp_posmo) +tm_borders(col ="red") +tm_shape(posmo) +tm_dots(col ="day_week", title ="Day of the Week")
Figure 4: Cartographic representation of trajectory points from six students compared between weekends and weekdays
4.2 Impact of the time of the day
Code
# load clean data posmo <-read_delim("posmo_data/posmo_trips.csv")# round datetime to 1h posmo_round <- posmo |>mutate(hour = lubridate::hour(datetime))# create dataframe, which calculates mean steplength, speed per hour over all dates comparing weekends and weekdaysposmo_day <- posmo_round |>group_by(hour, day_week)|>summarise(mean_dis =mean(trip_dis, na.rm =TRUE),mean_speed =mean(trip_speed, na.rm =TRUE),mean_duration =mean(trip_duration, na.rm =TRUE))
4.2.1 Spatial Analysis
The result for the trip distances per hour and weekday encourages the previous result of trip distance per travel mode, as both results show higher trip distances on the weekends compared to on weekdays. Otherwise the results do not show clear patterns. Maybe a slight decrease of the trip distances towards the end of the day.
Code
#| label: Mean trip distance per hour of the day compared between weekend/weekdayggplot(posmo_day, aes(hour, mean_dis, col = day_week)) +geom_point() +geom_line(lwd =0.7) +labs(title ="Mean Trip Distance over 24h", subtitle ="Compared between Weekend vs. Weekday", color ="Day of the Week") +scale_color_manual(values =c("weekday"="mediumpurple4", "weekend"="aquamarine3"), labels =c("Weekday", "Weekend")) +ylab("Mean Distance [m]") +xlab("Hour") +theme_minimal()
Figure 5: Mean trip distance for every hour of the day compared between weekdays and weekends
The pattern of a decreasing travel speed on the weekend towards the end of the day gets clearer in this result. Also, we found a higher trip speeds for weekends compared to on weekdays.
Code
ggplot(posmo_day, aes(hour, mean_speed, col = day_week)) +geom_point() +geom_line(lwd =0.7) +labs(title ="Mean Speed over 24h", subtitle ="Compared between Weekend vs. Weekday", color ="Day of the Week") +scale_color_manual(values =c("weekday"="mediumpurple4", "weekend"="aquamarine3"), labels =c("Weekday", "Weekend"))+ylab("Mean Speed [m/s]") +xlab("Hour") +theme_minimal()
Figure 6: Mean trip speed for every hour of the day compared between weekdays and weekends
4.2.2 Temproal Analysis
The trip duration seems to rise slightly on both weekends and weekdays towards the end of the day. Otherwise we could not detect any pattern in this result.
Code
ggplot(posmo_day, aes(hour, mean_duration/60, col = day_week)) +geom_point() +geom_line(lwd =0.7) +labs(title ="Mean Trip Duration over 24h", subtitle ="Compared between Weekend vs. Weekday", color ="Day of the Week") +ylab("Mean Duration [min]") +xlab("Hour") +scale_color_manual(values =c("weekday"="mediumpurple4", "weekend"="aquamarine3"), labels =c("Weekday", "Weekend")) +theme_minimal()
Figure 7: Mean trip duration for every hour of the day compared between weekdays and weekends
Table 2: Overview over the mean speed, distance and duration of travel modes compared between rainy or dry days, including their share
4.3.1 Spatial Analysis
Precipitation reduced trip distance by bike, foot, bus and car, while distance was higher for travel modes like train and tram. Rain had almost no effect on trip distance when travelling by horse. Although, travel distances are impacted by precipitation, the effect is only marginal.
Code
#| label: mean trip distance depending on precipitationggplot() +geom_boxplot(data = posmo, aes(rain_day, log(trip_dis), fill = rain_day)) +labs(title ="Trip Distance per Transport Mode", subtitle ="Comparing Precipitation vs. no Precipitation", fill ="Precipitation") +ylab("Log Distance [m]") +xlab("Transport Mode") +scale_fill_manual(values =c("rain"="lavenderblush3", "no_rain"="aquamarine3"), labels =c( "Precipitation", "No Precipitation")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())
Figure 8: Mean trip distance compared between precipiation and no/low precipitaion, where the trip distance is logarythmised
Speed at high precipitation is lower when travelling by bike, foot, bus and car, while for travel modes such as train and tram speed was higher. Travelling by horse was effected insignificantly by precipitation. Although, travel speeds are impacted by precipitation, the effect is only marginal.
Code
ggplot(posmo, aes(rain_day, log(trip_speed), fill = rain_day)) +geom_boxplot() +labs(title ="Trip Speed per Transport Mode", subtitle ="Comparing Precipitation vs. no Precipitation", fill ="Precipitation") +ylab("Log Speed [m/s]") +xlab("Transport Mode") +scale_fill_manual(values =c("rain"="lavenderblush3", "no_rain"="aquamarine3"), labels =c( "Precipitation", "No Precipitation")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())
Figure 9: Mean trip speed compared between precipiation and no/low precipitaion, where the trip speed is logarythmised
4.3.2 Temporal Analysis
The duration of trips was shorter under heavy precipitation by bike, bus and car, while students travelled longer by train and tram. Considering travelling by horse and foot, precipitation had only insignificant effects.
Code
ggplot() +geom_boxplot(data = posmo, aes(rain_day, trip_duration/60, fill = rain_day)) +labs(title ="Trip Duration per Transport Mode", subtitle ="Comparing Precipitation vs. no Precipitation", fill ="Precipitation") +ylab("Duration [min]") +xlab("Transport Mode") +scale_fill_manual(values =c("rain"="lavenderblush3", "no_rain"="aquamarine3"), labels =c( "Precipitation", "No Precipitation")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())
Figure 10: Mean trip duration compared between precipiation and no/low precipitaion
Code
# load weather stations legend <-read_delim("data/weather_legend.csv")# create sf object of joined dataweather <-st_as_sf(legend, coords =c("E","N"), crs =2056)# transform posmo data into an sf object posmo <-st_as_sf(posmo, coords =c("X","Y"), crs =2056) # 1. add grouping variable to the sf objectposmo_grouped <-group_by(posmo, dataset)# 2. use summarise() to "dissolve" all point into a multipoint objectposmo_smry <-summarise(posmo_grouped)# 3. run st_convex_hull()mcp_posmo <-st_convex_hull(posmo_smry)#choose map modetmap_mode("view")# segmented visualisation tm_shape(mcp_posmo) +tm_fill(col ="dataset", alpha =0.4, title ="Student") +tm_layout(title ="Cartographic Representation of Students travelling with/without Precipitation") +tm_shape(mcp_posmo) +tm_borders(col ="aquamarine3") +tm_shape(posmo) +tm_dots(col ="rain_day", title ="Precipitation") +tm_shape(weather) +tm_dots(title ="weather Stations")
Figure 11: Cartographic representation of trajectory points from six students compared between precipitation and no/low precipitation. Additionally, all weather stations used are visualised as black points on the map.
5 DISCUSSION
It is to be noted, that we investigated spatio-temporal movement patterns of students, which cannot be generalized, as it was shown that sociodemographics and travel behavior of university students differ from the general population and between students living on or off campus, as well as students attending urban or suburban campuses (Khattak et al., 2011). Travel behaviour is significantly impacted by age, income and life stage and these socio-demographic variables act in different ways to constrain or free types of travel behaviour (Kattiyapornpong & Miller, 2009).
In the course of this project it became clear, that the Posmo App comes with severe uncertainties and tracking errors. Quantifying those uncertainties would be subject to another semester project in itself, which is why we assumed that the data we used was correct.
5.1 Days of the Week Patterns
5.2 Influence of the Time of the Day
5.3 Precipiation Patterns
Precipitation impacted spatio-temporal movement patterns of students only in a marginal way, indicating no significant relationship between precipitation and movement patterns concerning several travel modes.
However, although only insignificant effects could be shown, some patterns were emerging as the movement (distance, speed and duration) of students was reduced under heavy rain when travelling by bike, bus and car, while it was increased when travelling by train and tram. This results are in contrast to Brum-Bastos et al. (2018), where they found a general trend of more vehicular use under heavy rain, while in our study we found e general decrease in the use of cars.
By foot it could only be shown that speed and distance were lower under heavy rain, while the duration was not impacted by precipitation patterns. In contrast to our finding, Brum-Bastos et al. (2018) found an overall decrease in walking during rain. The travel mode by horse showed no response in movement to precipitation.
It was shown, that when travel destinations are obligatory (e.g., work, lectures) people change their travel mode more likely under heavy rain, meaning that they drive to work instead of walk. However, if destinations are linked to leisure activities, people more likely just postpone the task instead of changing their travel mode (Connolly, 2008).
Additionally, during the week a decrease in public transport was observed under heavy rain by Brum-Bastos et al. (2018). This finding are in contrast to our results, where the use of some public transport means (train and tram) was increased under heavy rain, although we did not include the consideration of the days of the week.
However, it is to be said, that those marginal patterns found in our data is not indicative, as we only had a sample size of 5 students and investigated 11 days, from which 8 days were considered having heavy rainfall. Additionally, the results need to be interpreted with caution, as in fig. 11 it is shown, that for some trajectory points weather stations are rather far away to serve as indication for precipitation.
6 SOURCES
6.1 Data
Trajectory data of students: Posmo App
Weather data: https://gate.meteoswiss.ch/idaweb
6.2 Literature
Brum-Bastos, V. S., Long, J. A., & Demšar, U. (2018). Weather effects on human mobility: A study using multi-channel sequence analysis. Computers, Environment and Urban Systems, 71, 131–152. https://doi.org/10.1016/j.compenvurbsys.2018.05.004
Bundesamt für Statistik. (2021). Pendlermobilität. Bundesamt für Statistik. https://www.bfs.admin.ch/bfs/de/home/statistiken/mobilitaet-verkehr/personenverkehr/pendlermobilitaet.html
Bundesamt für Statistik. (2023, March 28). Studierende an den universitären Hochschulen: Basistabellen - 1990-2022 | Tabelle. Bundesamt für Statistik. https://www.bfs.admin.ch/asset/de/24345359
Connolly, M. (2008). Here Comes the Rain Again: Weather and the Intertemporal Substitution of Leisure. Source Journal of Labor Economics Journal of Labor Economics, 26(1), 73–100. https://doi.org/10.1086/522067
Kattiyapornpong, U., & Miller, K. E. (2009). Socio‐demographic constraints to travel behavior. International Journal of Culture, Tourism and Hospitality Research, 3(1), 81–94. https://doi.org/10.1108/17506180910940360
Khattak, A., Wang, X., Son, S., & Agnello, P. (2011). Travel by University Students in Virginia: Is This Travel Different from Travel by the General Population? Transportation Research Record: Journal of the Transportation Research Board, 2255(1). https://doi.org/10.3141/2255-15
Kyaing, K., Lwin, K., & Sekimoto, Y. (2017). Human mobility patterns for different regions in Myanmar based on CDRs data. IPTEK Journal of Proceedings Series, 3(6).
Liu, X., Sun, L., Sun, Q., & Gao, G. (2020). Spatial Variation of Taxi Demand Using GPS Trajectories and POI Data. Journal of Advanced Transportation, 2020, e7621576. https://doi.org/10.1155/2020/7621576
MeteoSwiss. (n.d.). Precipitation. Federal Office of Meterology and Climatology MeteoSwiss. Retrieved 19 June 2023, from https://www.meteoschweiz.admin.ch/wetter/wetter-und-klima-von-a-bis-z/niederschlag.html
Sathishkumar, Cho, Y., & Jangwoo, Park. (2020). Seoul bike trip duration prediction using data mining techniques. IET Intelligent Transport Systems, 14(11), 1465–1474. https://doi.org/10.1049/iet-its.2019.0796
Source Code
---title: "Effects of three environmental factors on spatio-temporal movement patterns of students"subtitle: "Project for Patterns and Trends in Environmental Data - Computational Movement Analysis"author: "Mirjam Scheib & Miriam Steinhauer"date: "07/02/2023"format: html: code-fold: true code-tools: true code-line-numbers: truehighlight-style: pygmentstable-of-contents: truenumber-sections: trueexecute: echo: true message: false eval: true warning: falseeditor: markdown: wrap: 72---# To Do's im Code- Rendern (Miri)- Summary tables nötig? bzw. wie am besten darstellen - Table beschriftungen? Nicht gleich wie figure beschriftung? Das geht nicht anders.. das haben sie im Best Practise auch so gemacht# BACKGROUND AND RESEARCH QUESTIONSIt is known that several factors like the weather condition (Brum-Bastos et al., 2018), the day of the week and time of the day (Liu et al., 2020; Sathishkumar et al., 2020) influence spatio-temporal movement patterns of people. There are several study’s investigating movement patterns of people in urban areas with the aim to improve the distribution of facilities and the provisioning of transportation services, as well as to manage traffic peaks (Kyaing et al., 2017; Liu et al., 2020). Nevertheless, most studies do not focus on specific social groups (e.g. workforce, students, pensioners), that might follow distinct spatio-temporal patterns, showing a potential demand for a specific adaption of infrastructure. The canton of Zurich accommodates the most students in Switzerland, with numbers continuing to rise (Bundesamt für Statistik, 2023). Additionally, students and apprentices (from the age of 15 years) make up 39 % of the public transport commuter mass, which is why knowledge of spatio-temporal patterns of students could help to manage train and other public transport infrastructure (Bundesamt für Statistik, 2021). Therefore, we want to investigate the influence of three environmental factors on spatio-temporal movement patterns of students, aiming to answer the following research questions: 1. Does the day of the week (weekend vs. workday) have an influence on the spatio-temporal movement patterns of students? 2. Does the time of the day compared between weekend and workday have an influence on the spatio-temporal movement patterns of students? 3. Does precipitation has an impact the spatio-temporal movement patterns of students?# DATA & METHODS## Data Primary data used in this project work consisted of trajectory data from 11 students collected with the Posmo App containing the following attributes:- **user_id:** entails the individual ID of the user (= student) (type: character)- **datetime:** date and time when a position of a user is tracked (type: datetime)- **weekday:** abbreviated name of the weekday (e.g. Mon = Monday) (type: character)- **place_name:** names of a place, in which a user is at a specific time (type: character)- **transport_mode:** the type of transport used by a user (e.g. car, bicycle, foot, train, other....) (type: character)- **lon_x/lat_y:** coordinates of the user at a specific time (type: numeric)Additionally, weather data from 84 stations in the canton of Zurich and bordering cantons (SZ, AG, ZG, TG, SG), consisting of measurements every 10 minutes was used to investigate the influence of precipitation on spatio-temporal movement patterns of students. ## Pre-processingFor the analysis first we reviewed data consistency by creating a point plot, where every tracking point in time (x-axis) was displayed per user (y-axis). Five users needed to be eliminated due to insufficient tracking point coverage in time. Additionally, the dataset was cut into a specific timeframe (28.04.2023 - 09.05.2023) covering 11 days to ensure sufficient overlap of tracking points between users in time. Additionally, travel modes consisting of “Airplane”, “Funicular” and “Other1” were removed, as they presented either too specific or unspecific travel modes to be of interest in the subsequent analysis. Furthermore, all convenience variables needed for the analysis were annotated in our pre-processing steps. First, it was discriminated between weekend (Sa – So) and weekdays (Mo – Fr). Additionally, to discriminate between days with high and low/no precipitation we calculated the nearest weather station for every trajectory point and annotated the precipitation data at the matching time to our dataset. We considered a precipitation of > 20 mm per 24 hours as a rainy day, as MeteoSwiss (n.d.) defines a precipitation from 10 – 30 mm per 24 hours as high intensity precipitation. To investigate spatio-temporal movement patterns of students in concern to environmental variables, we discriminated between static and movement segments and assigned to every moving sequence a segment ID. From this we calculated distance, speed and duration for every segment. All pre-processing steps can be accessed in a separate quarto-file (Pre_Processing.qmd) in our github respiratory under the following link: https://github.com/mirjamscheib/Semester_Project.git## AnalysisThe analysis of the research questions was carried out by creating summary tables and boxplots to investigate distance, speed and duration of different travel modes comparing weekends with weekdays and precipitation with no precipitation. Additionally, line plots visualising distance, speed and duration per hour of the day comparing weekends with weekdays were carried out. Cartographic maps visualising trajectory points of students comparing weekends with weekdays and precipitation and no precipitation complement the analysis. ```{r}#| label: load packages and clean data# clear space rm(list=ls())# load packages library("readr")library("dplyr")library("ggplot2")library("sf")library("terra")library("tmap")library("gitcreds")library("dplyr")library("SimilarityMeasures")library("lubridate")library("plotly")# load clean data posmo <-read_delim("posmo_data/posmo_trips.csv")```# RESULTS## Impact of the day of the week```{r}#| label: Table summary 1question1_summary <- posmo |>group_by(day_week, transport_mode) |>summarise(dis_mean =mean(trip_dis, na.rm = T),speed_mean =mean(trip_speed, na.rm = T),dur_mean =mean(trip_duration, na.rm = T)) |>mutate(perc_dis = dis_mean/sum(dis_mean)*100,perc_speed = speed_mean/sum(speed_mean)*100,perc_dur = dur_mean/sum(dur_mean)*100)question1_summary# knitr::opts_chunk$set(eval = FALSE)```Table 1: Overview over the mean speed, distance and duration of travel modes compared between weekdays and weekends, including their share ### Spatial AnalysisFor each travelmode we found a higher trip distance on weekends compared to weekdays. The trip distances for the travel mode "walk" have a lower mean than for other travel modes. On the other hand, the mean travel distances for "bike" are around the same range as for "car" and "train". ```{r, fig.cap = "Figure 1: Trip distance per transport mode compared between weekends and weekdays, the trip distance is logarythmised"}#| label: Boxplot comparing trip distance between weekend and weekday of travelmodesggplot() +geom_boxplot(data = posmo, aes(day_week, log(trip_dis), fill = day_week)) +labs(title ="Trip Distance per Transport Mode", subtitle ="Comparing Weekend vs. Weekday", fill ="Day of the Week") +ylab("Log Trip Distance [m]") +xlab("Transport Mode") +scale_fill_manual(values =c("weekday"="lavenderblush3", "weekend"="aquamarine3"), labels =c( "Weekday", "Weekend")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())```For trip speed, the results are not as clear as for trip distance, but there is a tendency of trip speed being higher on the weekends, than during the week. Again we find the mean trip speed of "bike" being in a similar range as "car" and "train", whereas "bus" conforms to "horse".```{r, fig.cap = "Figure 2: Trip speed per transport mode compared between weekends and weekdays, the trip speed is logarythmised"}#| label: Boxplot comparing trip speed between weekend and weekday of travelmodesggplot(posmo, aes(day_week, log(trip_speed), fill = day_week)) +geom_boxplot() +labs(title ="Trip Speed per Transport Mode", subtitle ="Comparing Weekend vs. Weekday", fill ="Day of the Week") +ylab("Log Speed [m/s]") +xlab("Transport Mode") +scale_fill_manual(values =c("weekday"="lavenderblush3", "weekend"="aquamarine3"), labels =c( "Weekday", "Weekend")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())```### Temporal AnalysisWe could not find a clear result concerning trip duration between weekends and weekdays. The only tendency that can be seen, is that the mean trip duration of "walk" is lower than for all the other travel modes.```{r, fig.cap = "Figure 3: Trip duration per transport mode compared between weekends and weekdays, the trip duration is logarythmised"}#| label: Boxplot comparing trip duration between weekend and weekday of travelmodesggplot() +geom_boxplot(data = posmo, aes(day_week, log(trip_duration/60), fill = day_week)) +labs(title ="Trip Duration per Transport Mode", subtitle ="Comparing Weekend vs. Weekday", fill ="Day of the Week") +ylab("Log Duration [min]") +xlab("Transport Mode") +scale_fill_manual(values =c("weekday"="lavenderblush3", "weekend"="aquamarine3"), labels =c( "Weekday", "Weekend")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())``````{r, fig.cap = "Figure 4: Cartographic representation of trajectory points from six students compared between weekends and weekdays"}#| label: prepro and creation of visual map with convex hull# transform posmo data into an sf object posmo <-st_as_sf(posmo, coords =c("X","Y"), crs =2056) # 1. add grouping variable to the sf objectposmo_grouped <-group_by(posmo, dataset)# 2. use summarise() to "dissolve" all point into a multipoint objectposmo_smry <-summarise(posmo_grouped)# 3. run st_convex_hull()mcp_posmo <-st_convex_hull(posmo_smry)# set visual modetmap_mode("view")# cartographic visualisation tm_shape(mcp_posmo) +tm_fill(col ="dataset", alpha =0.4, title ="Student") +tm_layout(title ="Cartographic Representation of Students travelling on Weekdays vs. Weekends") +tm_shape(mcp_posmo) +tm_borders(col ="red") +tm_shape(posmo) +tm_dots(col ="day_week", title ="Day of the Week")```## Impact of the time of the day```{r}#| label: prepro metrics for plots# load clean data posmo <-read_delim("posmo_data/posmo_trips.csv")# round datetime to 1h posmo_round <- posmo |>mutate(hour = lubridate::hour(datetime))# create dataframe, which calculates mean steplength, speed per hour over all dates comparing weekends and weekdaysposmo_day <- posmo_round |>group_by(hour, day_week)|>summarise(mean_dis =mean(trip_dis, na.rm =TRUE),mean_speed =mean(trip_speed, na.rm =TRUE),mean_duration =mean(trip_duration, na.rm =TRUE)) ```### Spatial AnalysisThe result for the trip distances per hour and weekday encourages the previous result of trip distance per travel mode, as both results show higher trip distances on the weekends compared to on weekdays. Otherwise the results do not show clear patterns. Maybe a slight decrease of the trip distances towards the end of the day. ```{r, fig.cap = "Figure 5: Mean trip distance for every hour of the day compared between weekdays and weekends"}#| label: Mean trip distance per hour of the day compared between weekend/weekdayggplot(posmo_day, aes(hour, mean_dis, col = day_week)) +geom_point() +geom_line(lwd =0.7) +labs(title ="Mean Trip Distance over 24h", subtitle ="Compared between Weekend vs. Weekday", color ="Day of the Week") +scale_color_manual(values =c("weekday"="mediumpurple4", "weekend"="aquamarine3"), labels =c("Weekday", "Weekend")) +ylab("Mean Distance [m]") +xlab("Hour") +theme_minimal()```The pattern of a decreasing travel speed on the weekend towards the end of the day gets clearer in this result. Also, we found a higher trip speeds for weekends compared to on weekdays. ```{r, fig.cap = "Figure 6: Mean trip speed for every hour of the day compared between weekdays and weekends"}#| label: Mean trip speed per hour of the day compared between weekend/weekdayggplot(posmo_day, aes(hour, mean_speed, col = day_week)) +geom_point() +geom_line(lwd =0.7) +labs(title ="Mean Speed over 24h", subtitle ="Compared between Weekend vs. Weekday", color ="Day of the Week") +scale_color_manual(values =c("weekday"="mediumpurple4", "weekend"="aquamarine3"), labels =c("Weekday", "Weekend"))+ylab("Mean Speed [m/s]") +xlab("Hour") +theme_minimal()```### Temproal AnalysisThe trip duration seems to rise slightly on both weekends and weekdays towards the end of the day. Otherwise we could not detect any pattern in this result. ```{r, fig.cap = "Figure 7: Mean trip duration for every hour of the day compared between weekdays and weekends"}#| label: Mean trip duration per hour of the day compared between weekend/weekdayggplot(posmo_day, aes(hour, mean_duration/60, col = day_week)) +geom_point() +geom_line(lwd =0.7) +labs(title ="Mean Trip Duration over 24h", subtitle ="Compared between Weekend vs. Weekday", color ="Day of the Week") +ylab("Mean Duration [min]") +xlab("Hour") +scale_color_manual(values =c("weekday"="mediumpurple4", "weekend"="aquamarine3"), labels =c("Weekday", "Weekend")) +theme_minimal()```## Impact of precipitation```{r}#| label: Table Summary 2#load clean dataposmo <-read_delim("posmo_data/posmo_trips.csv")question2_summary <- posmo |>group_by(rain_day, transport_mode) |>summarise(dis_mean =mean(trip_dis, na.rm = T),speed_mean =mean(trip_speed, na.rm = T),dur_mean =mean(trip_duration, na.rm = T)) |>mutate(perc_dis = dis_mean/sum(dis_mean)*100,perc_speed = speed_mean/sum(speed_mean)*100,perc_dur = dur_mean/sum(dur_mean)*100) |>subset(rain_day =="rain")question2_summary```Table 2: Overview over the mean speed, distance and duration of travel modes compared between rainy or dry days, including their share ### Spatial AnalysisPrecipitation reduced trip distance by bike, foot, bus and car, while distance was higher for travel modes like train and tram. Rain had almost no effect on trip distance when travelling by horse. Although, travel distances are impacted by precipitation, the effect is only marginal. ```{r, fig.cap = "Figure 8: Mean trip distance compared between precipiation and no/low precipitaion, where the trip distance is logarythmised"}#| label: mean trip distance depending on precipitationggplot() +geom_boxplot(data = posmo, aes(rain_day, log(trip_dis), fill = rain_day)) +labs(title ="Trip Distance per Transport Mode", subtitle ="Comparing Precipitation vs. no Precipitation", fill ="Precipitation") +ylab("Log Distance [m]") +xlab("Transport Mode") +scale_fill_manual(values =c("rain"="lavenderblush3", "no_rain"="aquamarine3"), labels =c( "Precipitation", "No Precipitation")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())```Speed at high precipitation is lower when travelling by bike, foot, bus and car, while for travel modes such as train and tram speed was higher. Travelling by horse was effected insignificantly by precipitation. Although, travel speeds are impacted by precipitation, the effect is only marginal. ```{r, fig.cap = "Figure 9: Mean trip speed compared between precipiation and no/low precipitaion, where the trip speed is logarythmised"}#| label: mean trip speed depending on precipitationggplot(posmo, aes(rain_day, log(trip_speed), fill = rain_day)) +geom_boxplot() +labs(title ="Trip Speed per Transport Mode", subtitle ="Comparing Precipitation vs. no Precipitation", fill ="Precipitation") +ylab("Log Speed [m/s]") +xlab("Transport Mode") +scale_fill_manual(values =c("rain"="lavenderblush3", "no_rain"="aquamarine3"), labels =c( "Precipitation", "No Precipitation")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())```### Temporal AnalysisThe duration of trips was shorter under heavy precipitation by bike, bus and car, while students travelled longer by train and tram. Considering travelling by horse and foot, precipitation had only insignificant effects. ```{r, fig.cap= "Figure 10: Mean trip duration compared between precipiation and no/low precipitaion"}#| label: mean trip duration depending on precipitationggplot() +geom_boxplot(data = posmo, aes(rain_day, trip_duration/60, fill = rain_day)) +labs(title ="Trip Duration per Transport Mode", subtitle ="Comparing Precipitation vs. no Precipitation", fill ="Precipitation") +ylab("Duration [min]") +xlab("Transport Mode") +scale_fill_manual(values =c("rain"="lavenderblush3", "no_rain"="aquamarine3"), labels =c( "Precipitation", "No Precipitation")) +facet_wrap(~transport_mode, nrow =1) +theme_minimal() +theme(axis.text.x=element_blank())``````{r, fig.cap = "Figure 11: Cartographic representation of trajectory points from six students compared between precipitation and no/low precipitation. Additionally, all weather stations used are visualised as black points on the map."}#| label: create visual map rain# load weather stations legend <-read_delim("data/weather_legend.csv")# create sf object of joined dataweather <-st_as_sf(legend, coords =c("E","N"), crs =2056)# transform posmo data into an sf object posmo <-st_as_sf(posmo, coords =c("X","Y"), crs =2056) # 1. add grouping variable to the sf objectposmo_grouped <-group_by(posmo, dataset)# 2. use summarise() to "dissolve" all point into a multipoint objectposmo_smry <-summarise(posmo_grouped)# 3. run st_convex_hull()mcp_posmo <-st_convex_hull(posmo_smry)#choose map modetmap_mode("view")# segmented visualisation tm_shape(mcp_posmo) +tm_fill(col ="dataset", alpha =0.4, title ="Student") +tm_layout(title ="Cartographic Representation of Students travelling with/without Precipitation") +tm_shape(mcp_posmo) +tm_borders(col ="aquamarine3") +tm_shape(posmo) +tm_dots(col ="rain_day", title ="Precipitation") +tm_shape(weather) +tm_dots(title ="weather Stations")```# DISCUSSION It is to be noted, that we investigated spatio-temporal movement patterns of students, which cannot be generalized, as it was shown that sociodemographics and travel behavior of university students differ from the general population and between students living on or off campus, as well as students attending urban or suburban campuses (Khattak et al., 2011). Travel behaviour is significantly impacted by age, income and life stage and these socio-demographic variables act in different ways to constrain or free types of travel behaviour (Kattiyapornpong & Miller, 2009). In the course of this project it became clear, that the Posmo App comes with severe uncertainties and tracking errors. Quantifying those uncertainties would be subject to another semester project in itself, which is why we assumed that the data we used was correct. ## Days of the Week Patterns## Influence of the Time of the Day## Precipiation Patterns Precipitation impacted spatio-temporal movement patterns of students only in a marginal way, indicating no significant relationship between precipitation and movement patterns concerning several travel modes. However, although only insignificant effects could be shown, some patterns were emerging as the movement (distance, speed and duration) of students was reduced under heavy rain when travelling by bike, bus and car, while it was increased when travelling by train and tram. This results are in contrast to Brum-Bastos et al. (2018), where they found a general trend of more vehicular use under heavy rain, while in our study we found e general decrease in the use of cars. By foot it could only be shown that speed and distance were lower under heavy rain, while the duration was not impacted by precipitation patterns. In contrast to our finding, Brum-Bastos et al. (2018) found an overall decrease in walking during rain. The travel mode by horse showed no response in movement to precipitation. It was shown, that when travel destinations are obligatory (e.g., work, lectures) people change their travel mode more likely under heavy rain, meaning that they drive to work instead of walk. However, if destinations are linked to leisure activities, people more likely just postpone the task instead of changing their travel mode (Connolly, 2008).Additionally, during the week a decrease in public transport was observed under heavy rain by Brum-Bastos et al. (2018). This finding are in contrast to our results, where the use of some public transport means (train and tram) was increased under heavy rain, although we did not include the consideration of the days of the week. However, it is to be said, that those marginal patterns found in our data is not indicative, as we only had a sample size of 5 students and investigated 11 days, from which 8 days were considered having heavy rainfall. Additionally, the results need to be interpreted with caution, as in fig. 11 it is shown, that for some trajectory points weather stations are rather far away to serve as indication for precipitation. # SOURCES## Data- **Trajectory data of students:** Posmo App - **Weather data:** https://gate.meteoswiss.ch/idaweb## Literature- Brum-Bastos, V. S., Long, J. A., & Demšar, U. (2018). Weather effects on human mobility: A study using multi-channel sequence analysis. Computers, Environment and Urban Systems, 71, 131–152. https://doi.org/10.1016/j.compenvurbsys.2018.05.004- Bundesamt für Statistik. (2021). Pendlermobilität. Bundesamt für Statistik. https://www.bfs.admin.ch/bfs/de/home/statistiken/mobilitaet-verkehr/personenverkehr/pendlermobilitaet.html- Bundesamt für Statistik. (2023, March 28). Studierende an den universitären Hochschulen: Basistabellen - 1990-2022 | Tabelle. Bundesamt für Statistik. https://www.bfs.admin.ch/asset/de/24345359- Connolly, M. (2008). Here Comes the Rain Again: Weather and the Intertemporal Substitution of Leisure. Source Journal of Labor Economics Journal of Labor Economics, 26(1), 73–100. https://doi.org/10.1086/522067- Kattiyapornpong, U., & Miller, K. E. (2009). Socio‐demographic constraints to travel behavior. International Journal of Culture, Tourism and Hospitality Research, 3(1), 81–94. https://doi.org/10.1108/17506180910940360- Khattak, A., Wang, X., Son, S., & Agnello, P. (2011). Travel by University Students in Virginia: Is This Travel Different from Travel by the General Population? Transportation Research Record: Journal of the Transportation Research Board, 2255(1). https://doi.org/10.3141/2255-15- Kyaing, K., Lwin, K., & Sekimoto, Y. (2017). Human mobility patterns for different regions in Myanmar based on CDRs data. IPTEK Journal of Proceedings Series, 3(6).- Liu, X., Sun, L., Sun, Q., & Gao, G. (2020). Spatial Variation of Taxi Demand Using GPS Trajectories and POI Data. Journal of Advanced Transportation, 2020, e7621576. https://doi.org/10.1155/2020/7621576- MeteoSwiss. (n.d.). Precipitation. Federal Office of Meterology and Climatology MeteoSwiss. Retrieved 19 June 2023, from https://www.meteoschweiz.admin.ch/wetter/wetter-und-klima-von-a-bis-z/niederschlag.html- Sathishkumar, Cho, Y., & Jangwoo, Park. (2020). Seoul bike trip duration prediction using data mining techniques. IET Intelligent Transport Systems, 14(11), 1465–1474. https://doi.org/10.1049/iet-its.2019.0796